package neusoft.yuejian_11.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import neusoft.yuejian_11.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class MyCollectClubFragment extends Fragment {

    private RadioGroup radioGroup;
    private RadioButton clubRadio;
    private RadioButton masterRadio;
    private RadioButton trainRadio;
    private MyCollectClubListFragment myCollectClubListFragment;
    private MyCollectMasterFragment myCollectMasterFragment;
    private MyCollectTrainFragment myCollectTrainFragment;
    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;


    public MyCollectClubFragment() {
        // Required empty public constructor
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        clubRadio = (RadioButton) view.findViewById(R.id.radio_club);
        masterRadio = (RadioButton) view.findViewById(R.id.radio_master);
        trainRadio =(RadioButton) view.findViewById(R.id.radio_train);


        clubRadio.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    myCollectClubListFragment = new MyCollectClubListFragment();
                    replaceFragment(myCollectClubListFragment);

                }
            }
        });
        masterRadio.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    myCollectMasterFragment = new MyCollectMasterFragment();
                    replaceFragment(myCollectMasterFragment);

                }
            }
        });
        trainRadio.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    myCollectTrainFragment = new MyCollectTrainFragment();
                    replaceFragment(myCollectTrainFragment);

                }
            }
        });
        fragmentManager = getChildFragmentManager();
        clubRadio.setChecked(true);
    }

    private void replaceFragment(Fragment fragment){
        transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fragment_holder, fragment);
        transaction.commit();
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_my_collect_club, container, false);
    }

}
